<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("comctrls.inc.php");
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("components4phpfull/jtdivwindow.inc.php");
use_unit("components4phpfull/jtgroupbox.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("components4phpfull/jtdatepicker.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class Cert_Edit extends Page
{
       public $lbldes = null;
       public $Label12 = null;
       public $JSValidate = null;
       public $hfError = null;
       public $edtDesc = null;
       public $btnCancel = null;
       public $btnSubmit = null;
       public $imgBack = null;
       public $dpLicenseRenew = null;
       public $JTJavaScript3 = null;
       public $JTJavaScript2 = null;
       public $JTJavaScript1 = null;
       public $compid = null;
       public $JTDivDesc = null;
       public $JTGroupBox1 = null;
       public $btnAddDesc = null;
       public $btnDelDesc = null;
       public $edDesc = null;
       public $listDesc = null;
       public $btnShowDesc = null;
       public $hiddenCert = null;
       public $hiddenEmp = null;
       public $Image1 = null;
       public $JTSiteTheme1 = null;
       public $memoComments = null;
       public $Label2 = null;
       public $Label1 = null;
       public $cmbdesc = null;
       public $Label3 = null;
       public $chkComplete = null;
       function edtDescJSBlur($sender, $params)
       {

       ?>
       //Add your javascript code here
       validateRequire('edtDesc','lbldes');
       <?php

       }

       function imgBackJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back.png"
       <?php

       }

       function imgBackJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back2.png"
       <?php

       }

       function btnDelDescJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var DescIndex = document.getElementById('listDesc').selectedIndex;
       var DescValue = document.getElementById('listDesc')[DescIndex].value;
       var comp = document.getElementById('compid').value;
       AjaxCert3(DescValue,comp);
       <?php

       }

       function btnAddDescJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var adddesc = document.getElementById('edDesc').value;
       var comp = document.getElementById('compid').value;
       AjaxCert2(adddesc,comp);
       document.Cert_Edit.edDesc.value = "";
       <?php

       }

       function btnShowDescJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('JTDivDesc').Show();
       document.Cert_Edit.edDesc.value = "";
       <?php

       }


       function btnCancelClick($sender, $params)
       {
       redirect('emp_certification_list.php?emp='.$this->hiddenEmp->getValue().'&cert='.$this->hiddenCert->getValue());


       }

       function btnSubmitClick($sender, $params)
       {
       $this->validateRequired($this->edtDesc->Text, 'lbldes');
       $error = $this->hfError->getValue();
       if($error == '1' || $number != $key)
       {
          $this->hfError->setValue('0');
          return false;
       }
       else if($error == '0')
       {

       if($this->chkComplete->Checked==true)
       {
       $complete = '1';
       }
       else
       {
       $complete = '0';
       }

       mysql_query("update emp_certification_tbl set
       cert_date ='".$this->dpLicenseRenew->Text."',
       description ='".$this->edtDesc->Text."',
       comments = '".$this->memoComments->Text."',
       completed = '".$complete."'
       where emp_id='".$this->hiddenEmp->getValue()."' and cert_id ='".$this->hiddenCert->getValue()."'")or die("UPDATE CERTIFICATION - " . mysql_error());

       redirect('emp_certification_list.php?emp='.$this->hiddenEmp->getValue().'&cert='.$this->hiddenCert->getValue());

       }
       }

       function validateRequired($value, $lbl)
       {
          if($value == '' || $value == null)
          {
             $this->$lbl->Caption = '&darr; This field is required &darr;';
             $this->hfError->setValue('1');
          }
       }

       function Cert_EditCreate($sender, $params)
       {
        $this->hfError->setValue('0');
       $this->lbldes->Caption = '';

       $this->compid->Value = $_SESSION['company_id'];
       $emp_id = $_GET['emp'];
       $cert_id = $_GET['cert'];
       $this->hiddenEmp->setValue($emp_id);
       $this->hiddenCert->setValue($cert_id);

       $this->imgBack->setLink('emp_certification_list.php?emp='.$this->hiddenEmp->getValue());

       $query_cert = "select * from emp_certification_tbl where company_id='".$_SESSION['company_id']."' and emp_id='".$this->hiddenEmp->getValue()."' and cert_id='".$this->hiddenCert->getValue()."'";
       $result_cert = mysql_query($query_cert)or die(mysql_error());
       $row_cert = mysql_fetch_array($result_cert);

       if($row_cert['completed']=="1")
       {
       $this->chkComplete->Checked=true;
       }
       else
       {
       $this->chkComplete->Checked=false;
       }

       $this->dpLicenseRenew->Text = $row_cert['cert_date'];
       $this->memoComments->Text = $row_cert['comments'];
       $this->edtDesc->Text = $row_cert['description'];

       $this->cmbdesc->Clear();
       $this->cmbdesc->ItemIndex=$row_cert['description'];
       $result_desc = mysql_query("select * from lookup_personnel_tbl where category='renewals/certifications'");

        while($row_desc = mysql_fetch_array($result_desc))
        {
            $this->cmbdesc->AddItem($row_desc['value'], null, $row_desc['value']);
        }

        //list description;
       $result_d = mysql_query("select * from lookup_personnel_tbl where company_id = '".$_SESSION['company_id']."' AND category='renewals/certifications'");

        while($row_d = mysql_fetch_array($result_d))
        {
            $this->listDesc->AddItem($row_d['value'], null, $row_d['value']);
        }
       }


}

global $application;

global $Cert_Edit;

//Creates the form
$Cert_Edit=new Cert_Edit($application);

//Read from resource file
$Cert_Edit->loadResource(__FILE__);

//Shows the form
$Cert_Edit->show();

?>